<template>
  <div>
       <el-form  :inline="true"   size="mini" >
        <div class="search-common">

             <el-form-item>
               <router-link :to="{name:'menu_operation_angent'}" tag="div"> 
                  <el-button type="primary">新增</el-button>
               </router-link>
           
          </el-form-item>
        </div>
        </el-form>
  <div class="mt10 p10" style="background:#fff">
        <br>
  <el-table
    :data="queryList"
    size="mini"
    :stripe="true"
    border
    style="width:99%">
    <el-table-column
      prop="agent_num"
      label="经纪商代码"
    >
    </el-table-column>
    <el-table-column
      prop="agent_name"
      label="经纪商名称"
     >
    </el-table-column>
     <el-table-column
      label="APP经纪商通用LOGO"
     >
      <template slot-scope="scope">
    <img  :src="scope.row.agent_logo" width="30" height="30" alt="APP经纪商通用LOGO"/>
  </template>
    </el-table-column>
    <el-table-column
      label="PC经纪商通用LOGO"
     >
      <template slot-scope="scope">
    <img  :src="scope.row.agent_logo_pc" width="30" height="30" alt="PC经纪商通用LOGO"/>
  </template>
    </el-table-column>

    <el-table-column
      label="启用状态"
    >
   <template slot-scope="scope">
     {{scope.row.status==1?'已启用':scope.row.status==0?'已停用':'其他'}}
  </template>
    </el-table-column>
     <el-table-column
      prop="agent_desc"
      label="经纪商简介"
    >
    </el-table-column>

    <el-table-column
      label="操作"
      width="150">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="editAngentItem(scope.row.id)">编辑</el-button>
         <el-button type="text" size="small" @click="deleteAngentItem(scope.row)" v-if="scope.row.status!=-1">
            {{scope.row.status==1?'停用':scope.row.status==0?'启用':'其他'}}
         </el-button>
      </template>
    </el-table-column>
    </el-table>
  </div>
  <page-pagination 
      v-on:pageFun="pageFunNumber" 
      :page="page" 
      :pageSize="pageSize" 
      :total="total">
    </page-pagination>

  </div>
</template>
<script>
import pagePagination from "@/components/Common/pagePagination";
import service from "@/service/index_c";
export default {
  components: {
      pagePagination
    },
  data() {
    return {
      page: 1,
      pageSize: 10,
      total: 0,
      queryList: [],
      title: "新增",
      postionDialog: false,
      editDialog: {}
    };
  },
  mounted() {
    this.queryAngentList();
  },
  methods: {
    pageFunNumber(page) {
       this.queryAngentList(page);
    },
    editAngentItem(id) {
      this.$router.push({ name: "menu_operation_angent", query: { id: id } });
    },
    async queryAngentList(page=1) {
      let res = await service.haibeiServerQueryAngentList();
      if (res.success) {
        this.queryList = res.result.pageList;
        this.page = res.result.page;
        this.total = res.result.nums;
      }
    },
    deleteAngentItem(row) {
      this.$confirm(
        `您确定要${
          row.status == 1 ? "停用" : row.status == 0 ? "启用" : "其他"
        }该条数据吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          lockScroll: false
        }
      )
        .then(() => {
          let st = row.status == 1 ? "0" : row.status == 0 ? "1" : "-1";
          service
            .haibeiServerUpdateStatusAngentItem({ id: row.id, status: st })
            .then(res => {
              if (res.success) {
                this.$message({
                  type: "success",
                  message: res.msg
                });
                this.queryAngentList();
                row.status = st;
              } else {
                this.$message({
                  type: "error",
                  message: res.msg
                });
              }
            });
        })
        .catch(() => {});
    }
  }
};
</script>

